<template>
  <div>
    <div class="banner">
      <banner/>
    </div>
    <div class="content">
      <h1>联系我们</h1>
      <el-card shadow="always">
        <div class="div-parent">
          <div class="div-contact">
            <div class="contact"><i class="el-icon-location-outline"></i></div>
            <div class="contact-text">地址：{{contactData.address}}</div>
          </div>
          <div class="div-contact">
            <div class="contact"><i class="el-icon-guide"></i></div>
            <div class="contact-text">邮编：{{contactData.code}}</div>
          </div>
          <div class="div-contact">
            <div class="contact"><i class="el-icon-phone"></i></div>
            <div class="contact-text">电话：{{contactData.mobilePhone}}</div>
          </div>
          <div class="div-contact">
            <div class="contact"><i class="el-icon-mobile-phone"></i></div>
            <div class="contact-text">手机：{{contactData.phone}}</div>
          </div>
          <div class="div-contact">
            <div class="contact"><i class="el-icon-chat-square"></i></div>
            <div class="contact-text">邮箱：{{contactData.email}}</div>
          </div>
        </div>
      </el-card>
      <h1>在线联系</h1>
      <el-card shadow="always" style="margin-bottom: 20px">
        <!--表单-->
        <div style="padding: 10px" >
          <el-form ref="form" :rules="rules" :model="form" label-width="80px" label-position="top">
            <el-form-item label-position="left" prop="name" >
              <el-input v-model="form.name" placeholder="您的名字" ></el-input>
            </el-form-item>
            <el-form-item label-position="left" prop="email">
              <el-input v-model="form.email" placeholder="您的邮箱" ></el-input>
            </el-form-item>
            <el-form-item label-position="left" prop="phone">
              <el-input v-model="form.phone" placeholder="您的电话" ></el-input>
            </el-form-item>
            <el-form-item prop="industry">
              <el-input v-model="form.industry" placeholder="所属行业" ></el-input>
            </el-form-item>
            <el-form-item prop="remark">
              <el-input type="textarea" v-model="form.remark" placeholder="留言"></el-input>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" @click="onSubmit" style="width: 100%">提交</el-button>
            </el-form-item>
          </el-form>
        </div>
      </el-card>
    </div>
  </div>
</template>

<script>
    import Banner from "../components/Banner";
    import { saveContactUs } from "../api"
    export default {
        name: "ContactUs",
        data(){
            return{
                activeName: '1',
                contactData:{
                    address:"哈尔滨市群里第五大道广发银行",
                    code:"150010",
                    phone:"17603629308",
                    mobilePhone:"17603629308",
                    email:"wlzb@aerosray.cn"
                },
                banners:[
                    { src:require("../assets/banner/contactUs/联系我们.jpg")},
                ],
                form:{
                    name:"",
                    email:"",
                    phone:"",
                    industry:"",
                    remark:"",
                    dataTime:null
                },
                rules: {
                    name: [
                        { required: true,message: '请输入姓名' }
                    ],
                    email: [
                        { required: true,message: '请输入邮箱' }
                    ],
                    phone: [
                        { required: true,message: '请输入电话' , trigger: 'blur' },
                        { pattern: /^1[3456789]\d{9}$/ , message: '请输入正确的电话', trigger: ['blur', 'change'] }
                    ],
                    industry: [
                        { required: true,message: '请输入所属行业' }
                    ],
                    remark: [
                        { required: true,message: '请输入留言内容不能为空' }
                    ]
                }
            }
        },
        methods: {
            onSubmit(){
                this.$refs.form.validate((valid)=>{
                    if (valid){
                        console.log(valid,"表单提交");
                        saveContactUs(this.form).then(({data})=>{
                            this.$message({
                                message: data.message,
                                type: data.type
                            });
                        });
                        this.$refs.form.resetFields();
                    }else{
                        console.log(valid,"校验不通过");
                    }
                });
            },
            handleClick(tab, event) {
            },
            setBanners(){
                //设置轮播图
                this.$store.commit("setBanners",this.banners);
            }
        },
        mounted(){
            this.setBanners();
        },
        components:{
            Banner,
        }
    }
</script>

<style scoped>
  @media screen and (max-width: 768px){

  }
  @media screen and (min-width: 768px){
    .div-parent{
      display:flex;
      justify-content:center;
    }
    .div-contact{
      width: 20%;
      display: inline-block;
      margin: 10px;
    }
  }
  /deep/ .el-tabs__item{
    font-size: 16px !important;
  }
  .content{
    padding: 0;
    margin-left: auto;
    margin-right: auto;
    width: 80%;
  }
  .contact{
    font-size: 50px;
    color: #409EFF;
    text-align: center;
  }
  .contact-text{
    text-align: center;
    font-size: 14px;
  }
  h1{
    color: #409EFF;
    font-size: 30px;
  }
</style>
